{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}

{% block title %}语音识别模型基准测试系统{% endblock %}

{% block page_content %}
<div class="page-header">
    <a href="{{ url_for('.tp',id=test_project.id) }}">返回{{ test_project.name }}测试项目页面</a>
    {% if is_edit %}
    <h1 id="action_title">编辑</h1>
    <p>只能修改用例名称、备注、预期采集的基准测试指标类型和模型的保存内容</p>
    {% else %}
    <h1 id="action_title">新增</h1>
    {% endif %}
</div>
<div class="col-md-4">
    <p>测试项目名称: <span id="name_span">{{ test_project.name }}</span></p>
    <p>语音识别模型：{% if test_project.model_id ==-1 %}无{% else %}<a href="{{ url_for('.m',id=test_project.model_id) }}">{{ model_name }}</a>{% endif %}</p>
    <p>语音的前端处理器（+语音的特征提取器）：{% if test_project.fp_id ==-1 %}无{% else %}<a href="{{ url_for('.ff',id=test_project.fp_id) }}">{{ fp_name }}</a>{% endif %}</p>
    <p>语音的特征提取器：{% if test_project.fe_id ==-1 %}无{% else %}<a href="{{ url_for('.ff',id=test_project.fe_id) }}">{{ fe_name }}</a>{% endif %}</p>
    <p>模型的训练数据预处理器：{% if test_project.train_dp_id ==-1 %}无{% else %}<a href="{{ url_for('.dp',id=test_project.train_dp_id) }}">{{ train_dp_name }}</a>{% endif %}</p>
    <p>模型的验证数据预处理器：{% if test_project.val_dp_id ==-1 %}无{% else %}<a href="{{ url_for('.dp',id=test_project.val_dp_id) }}">{{ val_dp_name }}</a>{% endif %}</p>
    <p>模型的测试数据预处理器：{% if test_project.test_dp_id ==-1 %}无{% else %}<a href="{{ url_for('.dp',id=test_project.test_dp_id) }}">{{ test_dp_name }}</a>{% endif %}</p>
    <form action="#" method="post">
        <p><label id="summary-error"></label></p>
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        <input type="hidden" name="id" value="{{ id }}" id="id-input">
        <input type="hidden" name="device_id_tip" value="{{ device_id }}" id="device-id-tip-input">
        <p>用例名称：<br>
            <input type="text" name="name" value="{{ name }}" required maxlength="20" id="name-input"><span id="name-err-msg" style="color:red;"></span>
        </p>
        <p>测试场景：<br>
        <select name="typ" id="typ-select" onchange="set_input_readonly4typ();">
            {% if typ==0 %}<option value="0" selected="selected">训练场景</option><option value="1">推理场景</option>{% elif typ==1 %}<option value="0">训练场景</option><option value="1" selected="selected">推理场景</option>{% endif %}
        </select></p>
        <p>计算设备：<br><select name="device_id" id="device-id-select" onchange="set_metrics4device_id();"></select><a href="{{ url_for('exec.detect_devices') }}">查询本服务器上的计算设备</a></p>
        <p>备注：<input type="text" value="{{ note }}" name="note" id="note-input"></p>
        <p>预期采集的基准测试指标类型：<br><span id="train-duration-span">{% if 'train_duration' in metrics %}<input type="checkbox" value="train_duration" name="metrics" checked id="train-duration-checkbox">{% else %}<input type="checkbox" value="train_duration" name="metrics" id="train-duration-checkbox">{% endif %}训练时长</span><span id="val-accuracy-span">{% if 'val_accuracy' in metrics %}<input type="checkbox" value="val_accuracy" name="metrics" checked id="val-accuracy-checkbox">{% else %}<input type="checkbox" value="val_accuracy" name="metrics" id="val-accuracy-checkbox">{% endif %}验证准确率</span><span id="accuracy-span">{% if 'accuracy' in metrics %}<input type="checkbox" value="accuracy" name="metrics" checked id="accuracy-checkbox">{% else %}<input type="checkbox" value="accuracy" name="metrics" id="accuracy-checkbox">{% endif %}准确率</span><span id="latency-span">{% if 'latency' in metrics %}<input type="checkbox" value="latency" name="metrics" checked id="latency-checkbox">{% else %}<input type="checkbox" value="latency" name="metrics" id="latency-checkbox">{% endif %}延迟</span><span id="throughput-span">{% if 'throughput' in metrics %}<input type="checkbox" value="throughput" name="metrics" checked id="throughput-checkbox">{% else %}<input type="checkbox" value="throughput" name="metrics" id="throughput-checkbox">{% endif %}吞吐量</span><span id="gpu-utility-span">{% if 'gpu_utility' in metrics %}<input type="checkbox" value="gpu_utility" name="metrics" checked id="gpu-utility-checkbox">{% else %}<input type="checkbox" value="gpu_utility" name="metrics" id="gpu-utility-checkbox">{% endif %}GPU利用率</span><span id="gpu-memory-utility-span">{% if 'gpu_memory_utility' in metrics %}<input type="checkbox" value="gpu_memory_utility" name="metrics" checked id="gpu-memory-utility-checkbox">{% else %}<input type="checkbox" value="gpu_memory_utility" name="metrics" id="gpu-memory-utility-checkbox">{% endif %}显存利用率</span><span id="gpu-memory-usage-span">{% if 'gpu_memory_usage' in metrics %}<input type="checkbox" value="gpu_memory_usage" name="metrics" checked id="gpu-memory-usage-checkbox">{% else %}<input type="checkbox" value="gpu_memory_usage" name="metrics" id="gpu-memory-usage-checkbox">{% endif %}显存使用量</span><span id="gpu-temperature-span">{% if 'gpu_temperature' in metrics %}<input type="checkbox" value="gpu_temperature" name="metrics" checked id="gpu-temperature-checkbox">{% else %}<input type="checkbox" value="gpu_temperature" name="metrics" id="gpu-temperature-checkbox">{% endif %}GPU温度</span><span id="gpu-power-span">{% if 'gpu_power' in metrics %}<input type="checkbox" value="gpu_power" name="metrics" checked id="gpu-power-checkbox">{% else %}<input type="checkbox" value="gpu_power" name="metrics" id="gpu-power-checkbox">{% endif %}GPU功率</span><span id="gpu-clock-frequency-span">{% if 'gpu_clock_frequency' in metrics %}<input type="checkbox" value="gpu_clock_frequency" name="metrics" checked id="gpu-clock-frequency-checkbox">{% else %}<input type="checkbox" value="gpu_clock_frequency" name="metrics" id="gpu-clock-frequency-checkbox">{% endif %}GPU时钟频率</span><span id="cpu-utility-span">{% if 'cpu_utility' in metrics %}<input type="checkbox" value="cpu_utility" name="metrics" checked id="cpu-utility-checkbox">{% else %}<input type="checkbox" value="cpu_utility" name="metrics" id="cpu-utility-checkbox">{% endif %}CPU利用率</span><span id="memory-usage-span">{% if 'memory_usage' in metrics %}<input type="checkbox" value="memory_usage" name="metrics" checked id="memory-usage-checkbox">{% else %}<input type="checkbox" value="memory_usage" name="metrics" id="memory-usage-checkbox">{% endif %}内存使用量</span></p>
        <p>音频变换方式：<br><input type="text" value="{{ audio_conversion }}" name="audio_conversion" id="audio-conversion-input"></p>
        <p id="model-save-dir-p">模型的保存目录：<br><input type="text" value="{{ model_save_dir }}" name="model_save_dir" id="model-save-dir-input"></p>
        <p id="model-save-style-p">保存的模型内容类型：<br><select name="model_save_style" id="model-save-style-select">{% if model_save_style==-1 %}<option value="-1" selected="selected"></option><option value="0">权重</option><option value="1">权重+模型结构</option>{% elif model_save_style==0 %}<option value="-1"></option><option value="0" selected="selected">权重</option><option value="1">权重+模型结构</option>{% elif model_save_style==1 %}<option value="-1"></option><option value="0">权重</option><option value="1" selected="selected">权重+模型结构</option>{% endif %}</select></p>
        <p id="train-stop-criterion-category-p">基准测试的结束指标类型：<br><select name="train_stop_criterion_category" id="train-stop-criterion-category-select">{% if train_stop_criterion_category==-1 %}<option value="-1" selected="selected"></option>{% else %}<option value="-1"></option>{% endif %}{% if train_stop_criterion_category==0 %}<option value="0" selected="selected">损失变化量</option>{% else %}<option value="0">损失变化量</option>{% endif %}{% if train_stop_criterion_category==1 %}<option value="1" selected="selected">验证准确率</option>{% else %}<option value="1">验证准确率</option>{% endif %}{% if train_stop_criterion_category==2 %}<option value="2" selected="selected">训练时间</option>{% else %}<option value="2">训练时间</option>{% endif %}{% if train_stop_criterion_category==3 %}<option value="3" selected="selected">迭代数</option>{% else %}<option value="3">迭代数</option>{% endif %}</select></p>
        <p id="train-stop-criterion-threshold-p">基准测试结束指标的阈值：<br><input type="text" value="{{ train_stop_criterion_threshold }}" name="train_stop_criterion_threshold" id="train-stop-criterion-threshold-input"><span id="train-stop-criterion-threshold-err-msg" style="color:red"></span></p>
        <p id="train-stop-criterion-times-p">基准测试结束条件的最少满足次数：<br><input type="number" value="{{ train_stop_criterion_times }}" name="train_stop_criterion_times" id="train-stop-criterion-times-input"></p>
        <p id="infer-stop-criterion-category-p">基准测试的结束指标类型：<br><select name="infer_stop_criterion_category" id="infer-stop-criterion-category-select">{% if infer_stop_criterion_category==-1 %}<option value="-1" selected="selected"></option>{% else %}<option value="-1"></option>{% endif %}{% if infer_stop_criterion_category==0 %}<option value="0" selected="selected">语音查询数量</option>{% else %}<option value="0">语音查询数量</option>{% endif %}{% if infer_stop_criterion_category==1 %}<option value="1" selected="selected">推理时长</option>{% else %}<option value="1">推理时长</option>{% endif %}</select></p>
        <p id="infer-stop-criterion-threshold-p">基准测试结束指标的阈值（推理时长的单位是秒）：<br><input type="text" name="infer_stop_criterion_threshold" value="{{ infer_stop_criterion_threshold }}" id="infer-stop-criterion-threshold-input"><span id="infer-stop-criterion-threshold-err-msg" style="color:red"></span></p>
        <p id="infer-scenario-category-p">推理场景的种类：<br><select name="infer_scenario_category" id="infer-scenario-category-select" onchange="set_request_config4online();">{% if infer_scenario_category==-1 %}<option value="-1" selected="selected"></option>{% else %}<option value="-1"></option>{% endif %}{% if infer_scenario_category==0 %}<option value="0" selected="selected">在线场景</option>{% else %}<option value="0">在线场景</option>{% endif %}{% if infer_scenario_category==1 %}<option value="1" selected="selected">离线场景</option>{% else %}<option value="1">离线场景</option>{% endif %}</select></p>
        <p id="infer-scenario-client-num-p">在线推理场景下的客户端数量：<br><input type="number" value="{{ infer_scenario_client_num }}" name="infer_scenario_client_num" id="infer-scenario-client-num-input"></p>
        <p id="infer-scenario-request-interval-distribution-p">在线推理场景下同一客户端所发送语音请求的时间间隔所服从的分布类型<br><select name="infer_scenario_request_interval_distribution" id="infer-scenario-request-interval-distribution-select" onchange="set_request_interval_distribution_params_tip();">{% if infer_scenario_request_interval_distribution==-1 %}<option value="-1" selected="selected" ></option>{% else %}<option value="-1"></option>{% endif %}{% if infer_scenario_request_interval_distribution==0 %}<option value="0" selected="selected">均匀分布</option>{% else %}<option value="0">均匀分布</option>{% endif %}{% if infer_scenario_request_interval_distribution==1 %}<option value="1" selected="selected">正态分布</option>{% else %}<option value="1">正态分布</option>{% endif %}{% if infer_scenario_request_interval_distribution==2 %}<option value="2" selected="selected">常量</option>{% else %}<option value="2">常量</option>{% endif %}{% if infer_scenario_request_interval_distribution==3 %}<option value="3" selected="selected">0（持续请求）</option>{% else %}<option value="3">0（持续请求）</option>{% endif %}{% if infer_scenario_request_interval_distribution==4 %}<option value="4" selected="selected">语音时长</option>{% else %}<option value="4">语音时长</option>{% endif %}</select></p>
        <p id="infer-scenario-request-interval-distribution-params-p">在线推理场景下同一客户端所发送语音请求的时间间隔所服从的分布参数：<br><input type="text" value="{{ infer_scenario_request_interval_distribution_params }}" name="infer_scenario_request_interval_distribution_params" id="infer-scenario-request-interval-distribution-params-input"><span id="infer-scenario-request-interval-distribution-params-tip"></span></p>
        <p>数据集名称：<br>
        <input type="text" name="dataset_name" id="dataset-name-input" value="{{ dataset_name }}" required><a class="btn btn-default" href="javascript:void(0)" onclick="select_dataset_name(1)">+</a></p>
        <div id="dataset-div"></div>
        <p>是否重新汇总数据集中的语音文件及其转录文本：<br>{% if summary_again %}<input type="radio" value="是" name="summary_again" checked="checked" id="summary-again-input">是<input type="radio" value="否" name="summary_again" id="summary-again-input">否{% else %}<input type="radio" value="是" name="summary_again" id="summary-again-input">是<input type="radio" value="否" name="summary_again" checked="checked" id="summary-again-input">否{% endif %}</p>
        <p>是否保持所有语音数据在内存中：<br>{% if maintain_data_all %}<input type="radio" value="是" name="maintain_data_all" checked="checked" id="maintain-data-all-input">是<input type="radio" value="否" name="maintain_data_all" id="maintain-data-all-input">否{% else %}<input type="radio" value="是" name="maintain_data_all" id="maintain-data-all-input">是<input type="radio" value="否" name="maintain_data_all" checked="checked" id="maintain-data-all-input">否{% endif %}</p>
                <p>后处理器名称：<br>
                    <input type="text" name="post_processor_name" id="post-processor-name-input" value="{{ post_processor_name }}"><a class="btn btn-default" href="javascript:void(0)" onclick="select_post_processor_name(1)" required>+</a></p>
                    <div id="post-processor-div"></div>
        <p>批量大小：<br><input type="number" name="batch_size" value="{{ batch_size }}" required id="batch-size-input"></p>
        <p id="checkpoint-iters-p">每多少轮训练迭代后获取模型的训练状态：<br><input type="text" name="checkpoint_iters" value="{{ checkpoint_iters }}" id="checkpoint-iters-input"><span id="checkpoint-iters-error-msg" style="color:red"></span></p>
        <p id="train-data-num-p">用于训练的语音文件数量：<br><input type="number" name="train_data_num" value="{{ train_data_num }}" id="train-data-num-input"></p>
        <p id="val-data-num-p">用于验证的语音文件数量：<br><input type="number" name="val_data_num" value="{{ val_data_num }}" id="val-data-num-input"></p>
        <p id="test-data-num-p">用于测试的语音文件数量：<br><input type="number" name="test_data_num" value="{{ test_data_num }}" id="test-data-num-input"></p>
        <p id="save-ckpt-interval-p">每获取多少次模型的训练状态后保存模型：<br><input type="number" name="save_ckpt_interval" value="{{ save_ckpt_interval }}" id="save-ckpt-interval-input"></p>
        <p>硬件开销指标数据的采集周期（以秒为单位）：<br><input type="number" name="hardware_cost_collection_interval" value="{{ hardware_cost_collection_interval }}" id="hardware-cost-collection-interval"></p>
        <p><input type="checkbox" value="executeRightnow" name="bExecutedRightnow" id="executed-rightnow-checkbox">提交后开始执行基准测试任务</p>
        <p><button type="submit" id="submit-input">提交</button><label id="disable-desc"></label></p>
    </form>
</div>
<script type="text/javascript">
    function select_dataset_name(page){
        var div_html='';
        $.getJSON('/exec/dataset?page='+page,function(data){
            let datasets=data['datasets'];
            let page_range=data['page_range'];
            for(let i=0;i<datasets.length;i++){
                div_html+='<a href="/datasubsets/'+datasets[i][0]+'">'+datasets[i][1]+'</a> <button onclick="$(\'#dataset-name-input\').val(\''+datasets[i][1]+'\');" type="button">选择</button> ';
            }
            if(div_html.length==0){
                div_html='暂时没有数据';
            }
            div_html+='<br><ul class="pagination">';
            for(let i=0;i<page_range.length;i++){
                if(page==page_range[i]){
                    div_html+='<li class="active">'+page+'</li>';
                }else{
                    div_html+='<li><a href="javascript:void(0)" onclick="select_dataset_name('+page_range[i]+')">'+page_range[i]+'</a></li>';
                }
            }
            div_html+='</ul>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/dataset_add">添加新的数据集</a>';
            $('#dataset-div').html(div_html);
        });
    };
    function select_post_processor_name(page){
        var div_html='';
        $.getJSON('/exec/post_processor?page='+page,function(data){
            let post_processors=data['post_processors'];
            let page_range=data['page_range'];
            for(let i=0;i<post_processors.length;i++){
                div_html+='<a href="/pp/'+post_processors[i][0]+'">'+post_processors[i][1]+'</a> <button onclick="$(\'#post-processor-name-input\').val(\''+post_processors[i][1]+'\');" type="button">选择</button> ';
            }
            if(div_html.length==0){
                div_html='暂时没有数据';
            }
            div_html+='<br><ul class="pagination">';
            for(let i=0;i<page_range.length;i++){
                if(page==page_range[i]){
                    div_html+='<li class="active">'+page+'</li>';
                }else{
                    div_html+='<li><a href="javascript:void(0)" onclick="select_post_processor_name('+page_range[i]+')">'+page_range[i]+'</a></li>';
                }
            }
            div_html+='</ul>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/post_processor_add">添加新的后处理器</a>';
            $('#post-processor-div').html(div_html);
        });
    };
    function check_bttask(){
        var check_list=new Array();
        $('input[name="metrics"]:checked').each(function(){
            check_list.push($(this).val());
        });
        if(check_list.length>0){
            $('input[name="metrics"]').val(check_list.join(','));
        }else{
            $('input[name="metrics"]').val('')
        }
        
        // 名称，浮点数的值是否合理
        var float_regs=/^(-?\d+)(\.\d+)?$/;
        var iters_regs=/^\d+[ie]$/;
        if((!float_regs.test($('#train-stop-criterion-threshold-input').val())&&!iters_regs.test($('#train-stop-criterion-threshold-input').val()))||$('#train-stop-criterion-threshold-input').val().length>10){
            $('#train-stop-criterion-threshold-err-msg').text('格式应为浮点数或数字+i或数字+e，字符串长度不超过10');
            $('#summary-error').text('训练停止条件的阈值格式应为浮点数或数字+i或数字+e，字符串长度不超过10');
            return false;
        }
        if(!float_regs.test($('#infer-stop-criterion-threshold-input').val())){
            $('#infer-stop-criterion-threshold-err-msg').text('请输入浮点数');
            $('#summary-error').text('请在推理停止条件的阈值输入框内输入浮点数');
            return false;
        }
        if(!iters_regs.test($('#checkpoint-iters-input').val())){
            $('#checkpoint-iters-error-msg').text('格式应为数字+i或数字+e');
            $('#summary-error').text('检查点之间的迭代间隔次数处的输入格式应为数字+i或数字+e');
            return false;
        }
        var name_pass;
        $.ajaxSetup({async:false});
        $.getJSON('/exec/check_bttask_name?name='+$('#name-input').val()+'&id='+$('#id-input').val(),function(data){
            name_pass=data['res'];
            if(!name_pass){
                $('#name-err-msg').text('语音识别模型的基准测试任务名称与已存在的语音识别模型的基准测试任务名称重复，请更名');
                $('#summary-error').text('语音识别模型的基准测试任务名称与已存在的语音识别模型的基准测试任务名称重复，请更名');
            }
        });
        console.log(name_pass);
        return name_pass;
    };
    $('#submit-input').click(check_bttask);
    function set_input_readonly4typ(){
        let value=$('#typ-select').val();
        if(value=='0'){
            // $('#train-duration-checkbox').removeAttr('disabled');
            // $('#val-accuracy-checkbox').removeAttr('disabled');
            // $('#accuracy-checkbox').attr('disabled','disabled');
            // $('#accuracy-checkbox').removeAttr('checked');
            // $('#latency-checkbox').attr('disabled','disabled');
            // $('#latency-checkbox').removeAttr('checked');
            // $('#model-save-dir-input').removeAttr('readonly');
            // $('#model-save-style-select').removeAttr('readonly');
            // $('#train-stop-criterion-category-select').removeAttr('readonly');
            // $('#train-stop-criterion-threshold-input').removeAttr('readonly');
            // $('#train-stop-criterion_times-input').removeAttr('readonly');
            // $('#infer-stop-criterion-category-select').attr('readonly','readonly');
            // $('#infer-stop-criterion-category-select').val('-1');
            // $('#infer-stop-criterion-threshold-input').attr('readonly','readonly');
            // $('#infer-scenario-category-select').attr('readonly','readonly');
            // $('#infer-scenario-category-select').val('-1');
            // $('#infer-scenario-request-interval-distribution-select').attr('readonly','readonly');
            // $('#infer-scenario-request-interval-distribution-select').val('-1');
            // $('#infer-scenario-request-interval-distribution-params-input').attr('readonly','readonly');
            // $('#train-data-preprocessor-name-input').removeAttr('readonly');
            // $('#val-data-preprocessor-name-input').removeAttr('readonly');
            // $('#test-data-preprocessor-name-input').attr('readonly','readonly');
            // $('#checkpoint-iters-input').removeAttr('readonly');
            // $('#train-data-num-input').removeAttr('readonly');
            // $('#val-data-num-input').removeAttr('readonly');
            // $('#test-data-num-input').attr('readonly','readonly');
            // $('#save-ckpt-interval-input').removeAttr('readonly');
            $('#train-duration-span').attr('style','display:inline;');
            $('#val-accuracy-span').attr('style','display:inline;');
            $('#accuracy-span').attr('style','display:none;');
            $('#accuracy-checkbox').removeAttr('checked');
            $('#latency-span').attr('style','display:none;');
            $('#latency-checkbox').removeAttr('checked');
            $('#model-save-dir-p').attr('style','display:block;');
            $('#model-save-style-p').attr('style','display:block;');
            $('#train-stop-criterion-category-p').attr('style','display:block;');
            $('#train-stop-criterion-threshold-p').attr('style','display:block;');
            $('#train-stop-criterion-times-p').attr('style','display:block;');
            $('#infer-stop-criterion-category-p').attr('style','display:none;');
            $('#infer-stop-criterion-category-select').val('-1');
            $('#infer-stop-criterion-threshold-p').attr('style','display:none;');
            $('#infer-scenario-category-p').attr('style','display:none;');
            $('#infer-scenario-category-select').val('-1');
            $('#infer-scenario-client-num-p').attr('style','display:none;');
            $('#infer-scenario-request-interval-distribution-p').attr('style','display:none;');
            $('#infer-scenario-request-interval-distribution-select').val('-1');
            $('#infer-scenario-request-interval-distribution-params-p').attr('style','display:none;');
            $('#checkpoint-iters-p').attr('style','display:block;');
            $('#train-data-num-p').attr('style','display:block;');
            $('#val-data-num-p').attr('style','display:block;');
            $('#test-data-num-p').attr('style','display:none;');
            $('#save-ckpt-interval-p').attr('style','display:block;');
        }else if(value=='1'){
            // $('#train-duration-checkbox').attr('disabled','disabled');
            // $('#train-duration-checkbox').removeAttr('checked');
            // $('#val-accuracy-checkbox').attr('disabled','disabled');
            // $('#val-accuracy-checkbox').removeAttr('checked');
            // $('#accuracy-checkbox').removeAttr('disabled');
            // $('#latency-checkbox').removeAttr('disabled');
            // $('#model-save-dir-input').attr('readonly','readonly');
            // $('#model-save-style-select').attr('readonly','readonly');
            // $('#train-stop-criterion-category-select').attr('readonly','readonly');
            // $('#train-stop-criterion-category-select').val('-1');
            // $('#train-stop-criterion-threshold-input').attr('readonly','readonly');
            // $('#train-stop-criterion_times-input').attr('readonly','readonly');
            // $('#infer-stop-criterion-category-select').removeAttr('readonly');
            // $('#infer-stop-criterion-threshold-input').removeAttr('readonly');
            // $('#infer-scenario-category-select').removeAttr('readonly');
            // $('#infer-scenario-request-interval-distribution-select').removeAttr('readonly');
            // $('#infer-scenario-request-interval-distribution-params-input').removeAttr('readonly');
            // $('#train-data-preprocessor-name-input').attr('readonly','readonly');
            // $('#val-data-preprocessor-name-input').attr('readonly','readonly');
            // $('#test-data-preprocessor-name-input').removeAttr('readonly');
            // $('#checkpoint-iters-input').attr('readonly','readonly');
            // $('#train-data-num-input').attr('readonly','readonly');
            // $('#val-data-num-input').attr('readonly','readonly');
            // $('#test-data-num-input').removeAttr('readonly');
            // $('#save-ckpt-interval-input').attr('readonly','readonly');
            $('#train-duration-span').attr('style','display:none;');
            $('#train-duration-checkbox').removeAttr('checked');
            $('#val-accuracy-span').attr('style','display:none;');
            $('#val-accuracy-checkbox').removeAttr('checked');
            $('#accuracy-span').attr('style','display:inline;');
            $('#latency-span').attr('style','display:inline;');
            $('#model-save-dir-p').attr('style','display:none;');
            $('#model-save-style-p').attr('style','display:none;');
            $('#train-stop-criterion-category-p').attr('style','display:none;');
            $('#train-stop-criterion-category-select').val('-1');
            $('#train-stop-criterion-threshold-p').attr('style','display:none;');
            $('#train-stop-criterion-times-p').attr('style','display:none;');
            $('#infer-stop-criterion-category-p').attr('style','display:block;');
            $('#infer-stop-criterion-threshold-p').attr('style','display:block;');
            $('#infer-scenario-category-p').attr('style','display:block;');
            // $('#infer-scenario-request-interval-distribution-p').attr('style','display:block;');
            // $('#infer-scenario-request-interval-distribution-params-p').attr('style','display:block;');
            $('#checkpoint-iters-p').attr('style','display:none;');
            $('#train-data-num-p').attr('style','display:none;');
            $('#val-data-num-p').attr('style','display:none;');
            $('#test-data-num-p').attr('style','display:block;');
            $('#save-ckpt-interval-p').attr('style','display:none;');
        }
    };
    set_input_readonly4typ();
    function initialize(callback){
        $.getJSON('/exec/detect_devices',function(data){
            let devices=data['devices'];
            let select_html='';
            var selected_val=$('#device-id-tip-input').val();
            for(let i=0;i<devices.length;i++){
                if(parseInt(selected_val)==devices[i]['device_id']){
                    select_html+='<option value="'+devices[i]['device_id']+'" selected="selected">'+devices[i]['name']+'</option>';
                }else{
                    select_html+='<option value="'+devices[i]['device_id']+'">'+devices[i]['name']+'</option>';
                }
            }
            $('#device-id-select').html(select_html);
            callback();
        });
    }
    // initialize();
    function set_metrics4device_id(){
        if($('#device-id-select').val()!='-1'){
            // $('#gpu-utility-checkbox').removeAttr('disabled');
            // $('#gpu-memory-utility-checkbox').removeAttr('disabled');
            // $('#gpu-memory-usage-checkbox').removeAttr('disabled');
            // $('#gpu-temperature-checkbox').removeAttr('disabled');
            // $('#gpu-power-checkbox').removeAttr('disabled');
            // $('#gpu-clock-frequency-checkbox').removeAttr('disabled');
            $('#gpu-utility-span').attr('style','display:inline;');
            $('#gpu-memory-utility-span').attr('style','display:inline;');
            $('#gpu-memory-usage-span').attr('style','display:inline;');
            $('#gpu-temperature-span').attr('style','display:inline;');
            $('#gpu-power-span').attr('style','display:inline;');
            $('#gpu-clock-frequency-span').attr('style','display:inline;');
        }else{
            // $('#gpu-utility-checkbox').attr('disabled','disabled');
            // $('#gpu-utility-checkbox').removeAttr('checked');
            // $('#gpu-memory-utility-checkbox').attr('disabled','disabled');
            // $('#gpu-memory-utility-checkbox').removeAttr('checked');
            // $('#gpu-memory-usage-checkbox').attr('disabled','disabled');
            // $('#gpu-memory-usage-checkbox').removeAttr('checked');
            // $('#gpu-temperature-checkbox').attr('disabled','disabled');
            // $('#gpu-temperature-checkbox').removeAttr('checked');
            // $('#gpu-power-checkbox').attr('disabled','disabled');
            // $('#gpu-power-checkbox').removeAttr('checked');
            // $('#gpu-clock-frequency-checkbox').attr('disabled','disabled');
            // $('#gpu-clock-frequency-checkbox').removeAttr('checked');
            $('#gpu-utility-span').attr('style','display:none;');
            $('#gpu-utility-checkbox').removeAttr('checked');
            $('#gpu-memory-utility-span').attr('style','display:none;');
            $('#gpu-memory-utility-checkbox').removeAttr('checked');
            $('#gpu-memory-usage-span').attr('style','display:none;');
            $('#gpu-memory-usage-checkbox').removeAttr('checked');
            $('#gpu-temperature-span').attr('style','display:none;');
            $('#gpu-temperature-checkbox').removeAttr('checked');
            $('#gpu-power-span').attr('style','display:none;');
            $('#gpu-power-checkbox').removeAttr('checked');
            $('#gpu-clock-frequency-span').attr('style','display:none;');
            $('#gpu-clock-frequency-checkbox').removeAttr('checked');
        }
    };
    initialize(set_metrics4device_id);
    function set_request_config4online(){
        if($('#infer-scenario-category-select').val()=='0'){
            // $('#infer-scenario-client-num-input').removeAttr('readonly');
            // $('#infer-scenario-request-interval-distribution-select').removeAttr('readonly');
            // $('#infer-scenario-request-interval-distribution-params-input').removeAttr('readonly');
            $('#infer-scenario-client-num-p').attr('style','display:block;');
            $('#infer-scenario-request-interval-distribution-p').attr('style','display:block;');
            $('#infer-scenario-request-interval-distribution-params-p').attr('style','display:block;');
        }else{
            // $('#infer-scenario-client-num-input').attr('readonly','readonly');
            // $('#infer-scenario-request-interval-distribution-select').attr('readonly','readonly');
            // $('#infer-scenario-request-interval-distribution-select').val('-1');
            // $('#infer-scenario-request-interval-distribution-params-input').attr('readonly','readonly');
            $('#infer-scenario-client-num-p').attr('style','display:none;');
            $('#infer-scenario-request-interval-distribution-p').attr('style','display:none;');
            $('#infer-scenario-request-interval-distribution-select').val('-1');
            $('#infer-scenario-request-interval-distribution-params-p').attr('style','display:none;');
        }
    }
    set_request_config4online();
    function set_request_interval_distribution_params_tip(){
        if($('#infer-scenario-request-interval-distribution-select').val()=='0'){
            $('#infer-scenario-request-interval-distribution-params-tip').text('请填写“a,b”，a表示均匀分布的区间的下界，b表示均匀分布的区间的上界');
            $('#infer-scenario-request-interval-distribution-params-input').removeAttr('readonly');
        }else if($('#infer-scenario-request-interval-distribution-select').val()=='1'){
            $('#infer-scenario-request-interval-distribution-params-tip').text('请填写“a,b”，a表示正态分布的数学期望，b表示正态分布的标准差');
            $('#infer-scenario-request-interval-distribution-params-input').removeAttr('readonly');
        }else if($('#infer-scenario-request-interval-distribution-select').val()=='2'){
            $('#infer-scenario-request-interval-distribution-params-tip').text('请填写“a”，表示请求按照a时间间隔均匀地被发出');
            $('#infer-scenario-request-interval-distribution-params-input').removeAttr('readonly');
        }else{
            $('#infer-scenario-request-interval-distribution-params-input').val('');
            $('#infer-scenario-request-interval-distribution-params-input').attr('readonly','readonly');
            $('#infer-scenario-request-interval-distribution-params-tip').text('')
        }
    }
    set_request_interval_distribution_params_tip();
    
    $(document).ready(function(){
        if($('#action_title').text()=='编辑'){
            $('#typ-select').attr('disabled','disabled');
            $('#device-id-select').attr('disabled','disabled');
            $('#audio-conversion-input').attr('disabled','disabled');
            $('#model-save-dir-input').attr('disabled','disabled');
            $('#train-stop-criterion-category-select').attr('disabled','disabled');
            $('#train-stop-criterion-threshold-input').attr('disabled','disabled');
            $('#train-stop-criterion-times-input').attr('disabled','disabled');
            $('#infer-stop-criterion-category-select').attr('disabled','disabled');
            $('#infer-stop-criterion-threshold-input').attr('disabled','disabled');
            $('#infer-scenario-category-select').attr('disabled','disabled');
            $('#infer-scenario-client-num-input').attr('disabled','disabled');
            $('#infer-scenario-request-interval-distribution-select').attr('disabled','disabled');
            $('#infer-scenario-request-interval-distribution-params-input').attr('disabled','disabled');
            $('#dataset-name-input').attr('disabled','disabled');
            $('#summary-again-input').attr('disabled','disabled');
            $('#maintain-data-all-input').attr('disabled','disabled');
            $('#post-processor-name-input').attr('disabled','disabled');
            $('#batch-size-input').attr('disabled','disabled');
            $('#checkpoint-iters-input').attr('disabled','disabled');
            $('#train-data-num-input').attr('disabled','disabled');
            $('#val-data-num-input').attr('disabled','disabled');
            $('#test-data-num-input').attr('disabled','disabled');
            $('#hardware-cost-collection-interval').attr('disabled','disabled');
            $('#executed-rightnow-checkbox').attr('disabled','disabled');
            // $('#typ-select').attr('style','display:none;');
            // $('#device-id-select').attr('style','display:none;');
            // $('#audio-conversion-input').attr('style','display:none;');
            // $('#model-save-dir-input').attr('style','display:none;');
            // $('#train-stop-criterion-category-select').attr('style','display:none;');
            // $('#train-stop-criterion-threshold-input').attr('style','display:none;');
            // $('#train-stop-criterion-times-input').attr('style','display:none;');
            // $('#infer-stop-criterion-category-select').attr('style','display:none;');
            // $('#infer-stop-criterion-threshold-input').attr('style','display:none;');
            // $('#infer-scenario-category-select').attr('style','display:none;');
            // $('#infer-scenario-client-num-input').attr('style','display:none;');
            // $('#infer-scenario-request-interval-distribution-select').attr('style','display:none;');
            // $('#infer-scenario-request-interval-distribution-params-input').attr('style','display:none;');
            // $('#dataset-name-input').attr('style','display:none;');
            // $('#summary-again-input').attr('style','display:none;');
            // $('#maintain-data-all-input').attr('style','display:none;');
            // $('#fp-name-input').attr('style','display:none;');
            // $('#fe-name-input').attr('style','display:none;');
            // $('#train-data-preprocessor-name-input').attr('style','display:none;');
            // $('#val-data-preprocessor-name-input').attr('style','display:none;');
            // $('#test-data-preprocessor-name-input').attr('style','display:none;');
            // $('#post-processor-name-input').attr('style','display:none;');
            // $('#model-name-input').attr('style','display:none;');
            // $('#batch-size-input').attr('style','display:none;');
            // $('#checkpoint-iters-input').attr('style','display:none;');
            // $('#train-data-num-input').attr('style','display:none;');
            // $('#val-data-num-input').attr('style','display:none;');
            // $('#test-data-num-input').attr('style','display:none;');
            // $('#hardware-cost-collection-interval').attr('style','display:none;');
            // $('#executed-rightnow-checkbox').attr('style','display:none;');
        }
        $.ajax({
            type:'GET',
            url:'/bttask_able2bEdited/'+$('#id-input').val(),
            success:function(data,status,request){
                editable=data['data'];
                if(!editable){
                    $('#submit-input').attr('disabled','disabled');
                    $('#disable-disc').text('该任务正在被占用，无法更改');
                }
            },
            error:function(){
                alert('请求id为'+$('#id-input').val()+'的基准测试任务能否被更改过程中出现错误');
            }
        });
    });
</script>
{% endblock %}